Skip to content

Sheet core: parts, keys, layers, and winner provenance (#443) - #464

Merged
samitbasu merged 2 commits into
mainfrom
sheet-443
Nov 21, 2026
Merged

samitbasu merged 2 commits into
mainfrom
sheet-443

Conversation

@samitbasu

Copy link
Copy Markdown
Owner

Part of #443 (epic #446), Sheet PR 1 of the approved note. No widget is on the sheet yet.

What it adds

  • Part (Base UI names, data-slot string, SOURCE), Key (variant, size, attr, aria, and negated attr/aria), When (up to four keys; not_aria, not_attr), Aria::HasPopup.
  • Sheet as a field of core Style: rule, replace, resolve, keys. The preset constructor (Shadcn::style) hands out the sheet at the preset layer, so the light and dark halves each carry their own.
  • Layers (defaults, preset, app, scope, ancestor, call site, important). The writer's layer is set by whoever hands out the sheet: as_preset, as_app, and Builder::styled for scope.
  • Builder::part: resolves a part's classes and returns them as the base of the node's own classes (merge the call site over them). Reports MissingStyleEntry for a variant or size the sheet names others of but not this one.
  • Q3: ancestor rules now go between the sheet and the call site (Rules::apply_layered); a node with no sheet takes the old path unchanged.
  • Provenance (debug builds only): Tw::origin_of(Property) gives the layer and source (Rust call site, or Shadcn file/line/class via Tw::sourced) of each property's winner. Every class method is #[track_caller]; the property list now names box paint and text properties too. Release builds carry none of it (Tw stays 840 bytes there).

Where it differs from the note

  • Memo lives in the builder state, not in the Sheet. taffy::Style holds a *const (), so a Tw is not Send, and a Style must be (it lives in egui's data). The sheet therefore stores each rule's body as an Fn(Tw) -> Tw + Send + Sync, and Builder::part memoises by (sheet version, part, keys) in BuildState. Sheet::resolve itself runs the bodies (for tests and tools).
  • b.part(..) returns the base already layered, so the widget just merges its call site over it. No second builder entry was needed, and every existing entry point accepts it.
  • replace drops every lower rule that holds with it (the note's "start empty"), not only same-keyed ones.
  • Not in this PR: the full override chain, tracing, the F12 pane, why (PR 2). Nodes do not keep their origins yet; Tw does.
  • Provenance covers layout, radii, opacity, box paint and text; not per-state variants (hover: and the like) yet.

Cost

Interleaved bench binaries (main at the base vs this branch), 4 rounds:

  • rule-free grid and text build, 100 and 1,000 nodes: no slower (this branch 2–4 % faster, within layout noise).
  • rules scenario (own classes vs rule): unchanged.
  • new sheet scenario (1,000 buttons, layout phase): own classes 5.05 ms, sheet part 5.35 ms, +6 %, from the layered apply, merge and memo clone per node.

Tests

tests/it/sheet.rs (through the real builder): keys, call site over sheet, ancestor rules between, slot matching, layer order, replace, the missing-variant report, negated keys, preset layer. Unit tests for provenance, merge, layered apply and Sheet. Clippy, fmt and the full workspace tests pass; the release-gates profile compiles clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AJYxo4YJZUXcPJ1bHdAHKy

A `Style` gains a `Sheet`: for each part of a widget (a `Part` enum with a
`data-slot` string), rules `(When, Tw body, layer)`. `Sheet::resolve` merges
the rules whose keys hold, lowest layer first, later winning per property;
`replace` drops what is below it. `When` asks for variant, size, attribute,
ARIA state, and their negations (`not_aria`, `not_attr`); `Aria` gains
`HasPopup`. Layers: defaults, preset, app, scope, ancestor, call site,
important; the writer's layer is set by whoever hands out the sheet
(`as_preset`, `as_app`, `Builder::styled` for scope).

`Builder::part` resolves a part's classes (memoised per build, as a `Tw`
is not `Send`) and returns them as the base of the node's own classes; the
rules of the containers above now go between that base and the call site
(`Rules::apply_layered`), as CSS gives shadcn's `[&_svg]:size-3` over an
icon's default but under a caller's explicit class. A node with no sheet is
built exactly as before.

In debug builds a `Tw` records which class, in which layer, set each
property (`Tw::origin_of`): every class method is `#[track_caller]`, and the
property list now names box paint and text properties too. Release builds
carry none of it.

Behavior changes: none for existing widgets (no widget is on the sheet yet).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AJYxo4YJZUXcPJ1bHdAHKy
@samitbasu

Copy link
Copy Markdown
Owner Author

Approved by the user on its tests and bench (2026-11-20). GitHub's required checks pass on the branch merged with current main. Merging.

@samitbasu
samitbasu merged commit 922f745 into main Nov 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant